<?php
  include("../conn/conn.php");
  $title=$_POST[title];
  $content=$_POST[EditorDefault];
  //$time=date("Y-m-j H:i:s");



if($_FILES['upfile']!="")
{
$sql=mysql_query("select * from tb_banner where id=".$_GET[id]."",$conn);
$info=mysql_fetch_array($sql);
@unlink("../".substr($info[tupian],6,(strlen($info[image])-6)));
}
function getname($exname){
   $dir = "../upimages/";
   $i=1;
   if(!is_dir($dir)){
      mkdir($dir,0777);
   }

	 $name=time().".".$exname;
   return $dir.$name;
}

$exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
$uploadfile = getname($exname);

move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile);

$uploadfile="admin/".substr($uploadfile,3);

if($_FILES['upfile']!=""){

	mysql_query("update tb_banner set title='$title',content='$content', image='$uploadfile' where id='".$_POST[id]."'",$conn);
} else {
  mysql_query("update tb_banner set title='$title',content='$content' where id='".$_POST[id]."'",$conn);

}
  echo "<script>alert('修改成功!');window.location.href='../adminbanner.php';</script>";
?>